2020-2021 Sunseeker Telemetry and Lighting System
eusci_b_i2c_ex4_masterTxSingle.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //*****************************************************************************
68 //
69 //*****************************************************************************
70 #include "driverlib.h"
71 
72 //*****************************************************************************
73 //
74 //Set the address for slave module. This is a 7-bit address sent in the
75 //following format:
76 //[A6:A5:A4:A3:A2:A1:A0:RS]
77 //
78 //A zero in the "RS" position of the first byte means that the master
79 //transmits (sends) data to the selected slave, and a one in this position
80 //means that the master receives data from the slave.
81 //
82 //*****************************************************************************
83 #define SLAVE_ADDRESS 0x48
84 
85 //*****************************************************************************
86 //
87 //Target frequency for SMCLK in kHz
88 //
89 //*****************************************************************************
90 #define CS_SMCLK_DESIRED_FREQUENCY_IN_KHZ 1000
91 
92 //*****************************************************************************
93 //
94 //SMCLK/FLLRef Ratio
95 //
96 //*****************************************************************************
97 #define CS_SMCLK_FLLREF_RATIO 30
98 
99 uint8_t transmitData;
100 
101 void main (void)
102 {
103  WDT_A_hold(WDT_A_BASE);
104 
105  //Set Ratio and Desired MCLK Frequency and initialize DCO
106  CS_initFLLSettle(
109  );
110 
111  //Set SMCLK = DCO with frequency divider of 1
112  CS_initClockSignal(
113  CS_SMCLK,
114  CS_DCOCLKDIV_SELECT,
115  CS_CLOCK_DIVIDER_1
116  );
117 
118  //Set MCLK = DCO with frequency divider of 1
119  CS_initClockSignal(
120  CS_MCLK,
121  CS_DCOCLKDIV_SELECT,
122  CS_CLOCK_DIVIDER_1
123  );
124 
125  // Configure Pins for I2C
126  /*
127  * Select Port 5
128  * Set Pin 2, 3 to input with function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
129  */
130  GPIO_setAsPeripheralModuleFunctionInputPin(
131  GPIO_PORT_P5,
132  GPIO_PIN2 + GPIO_PIN3,
133  GPIO_PRIMARY_MODULE_FUNCTION
134  );
135 
136  /*
137  * Disable the GPIO power-on default high-impedance mode to activate
138  * previously configured port settings
139  */
140  PMM_unlockLPM5();
141 
142  //Initialize transmit data packet
143  transmitData = 0x01;
144 
145  //Initialize Master
146  EUSCI_B_I2C_initMasterParam param = {0};
147  param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
148  param.i2cClk = CS_getSMCLK();
149  param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_400KBPS;
150  param.byteCounterThreshold = 1;
151  param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
152  EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
153 
154  //Specify slave address
155  EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE,
157  );
158 
159  //Set in transmit mode
160  EUSCI_B_I2C_setMode(EUSCI_B0_BASE,
161  EUSCI_B_I2C_TRANSMIT_MODE
162  );
163 
164  //Enable I2C Module to start operations
165  EUSCI_B_I2C_enable(EUSCI_B0_BASE);
166 
167  while (1)
168  {
169  //Send single byte data.
170  EUSCI_B_I2C_masterSendSingleByte(EUSCI_B0_BASE,
172  );
173 
174  //Delay until transmission completes
175  while (EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE)) ;
176 
177  //Delay between each transaction
178  __delay_cycles(50);
179 
180  //Increment transmit data counter
181  transmitData++;
182  }
183 }
void main(void)
uint8_t transmitData
#define CS_SMCLK_FLLREF_RATIO
#define CS_SMCLK_DESIRED_FREQUENCY_IN_KHZ
#define SLAVE_ADDRESS
MPU_initThreeSegmentsParam param
__delay_cycles(500000)